package ice.hufs.ac.kr.push;


import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

public class NetworkThread_Visit extends Thread {
	
	NetworkData nd;
	Handler mHandler;
	int commandState; 
	private final String SERVER_ADDRESS = "http://dislab.iptime.org:2795/requestinfo/visit_request.php"; 
	
	public static final int REGISTER = 0;
	
	public NetworkThread_Visit(NetworkData nd, Handler mHandler) {
		this.nd = nd;
		this.mHandler = mHandler;
	}
	
	public void setCommand(int command) {
		this.commandState = command;
	}
	
	public void run() {
		Looper.prepare();
		if(commandState == REGISTER) {
			register();	
		}
		
		Looper.loop();
	}
	
	private void register() {
		
//		String ID = nd.getId();
//		String PassWord = nw.getPassWord();
//		String ParentName = nd.getParentName();
//		String ParentPhoneNumber = nd.getParentPhoneNumber();
//		String VisitPurpose = nd.getVisitPurpose();
		String VisitDate = nd.getVisitDate();
		String VisitTime = nd.getVisitTime();
		String KeyValue = nd.getKeyValue();
		
		PageStreamer ps = new PageStreamer();
		ps.setRootURL(SERVER_ADDRESS);
//		ps.add("Id", ID);
//		ps.add("PassWord", PassWord);
//		ps.add("ParentName", ParentName);
//		ps.add("ParentPhoneNumber", ParentPhoneNumber);
//		ps.add("VisitPurpose", VisitPurpose);
		ps.add("VisitDate", VisitDate);
		ps.add("VisitTime", VisitTime);
		ps.add("KeyValue", KeyValue);
		
		String returnMsg = ps.getPageStream();
		Message msg = new Message();
		if(returnMsg.contains("1")) {
			msg.obj = returnMsg;
		}
		mHandler.sendMessage(msg);
	}
}
